name: buildcheck
on: [push]
jobs:
  build:
    if: github.event.repository.owner.login == 'StarRocks'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          repository: StarRocks/docs-site
          path: './docstmp'
          ssh-key: ${{ secrets.DOCS_SITE_KEY }}
      - uses: actions/cache@v3
        id: cache
        with:
          path: ./docstmp/node_modules
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
      - uses: actions/setup-node@v3
        with:
          node-version: '14'
      - name: Install Dependencies
        if: steps.cache.outputs.cache-hit != 'true'
        run: |
          cd ./docstmp
          npm install -E
      - name: Extract branch
        id: extract_branch
        run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
      - name: Extract locale
        id: extract_locale
        run: echo "##[set-output name=locale;]$(echo ${{github.event.repository.name}} | awk '{split($1, arr, "."); print arr[2]}')"
      - name: Build docs
        env: 
          DOC_VERSION: ${{ steps.extract_branch.outputs.branch }}
          DOC_LOCALE: ${{ steps.extract_locale.outputs.locale || 'en-us' }}
        run: |
          cd ./docstmp
          npm run clone
          npm run build
